package com.mobile.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.mobile.persistent.entity.Users;

public class AccessValidateInterceptor extends HandlerInterceptorAdapter {

	@Override
	public void postHandle(HttpServletRequest httpservletrequest,
			HttpServletResponse httpservletresponse, Object obj,
			ModelAndView modelandview) throws Exception {
		// TODO Auto-generated method stub
		super.postHandle(httpservletrequest, httpservletresponse, obj, modelandview);
	}

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		Users user=(Users) request.getSession().getAttribute("LoginUser");
		// 没有session
        if(user==null){
        	if(request.getRequestURI().indexOf("login") >= 0){
        		return true;
        	}else{ //而且不是登录页面
            	response.sendRedirect("login.do");
                return false;
        	}
        }
        return true;
	}

}
